/*
 * @lc app=leetcode.cn id=2760 lang=csharp
 *
 * [2760] 最长奇偶子数组
 */

// @lc code=start
public class Solution {
    public int LongestAlternatingSubarray(int[] nums, int threshold) {
        int left = 0, right = nums.Length - 1;
        
        while(left < right){
            if( nums[left] % 2 != 0)
            {
                left++;
                continue;
            }
            int index = left;
            while(index < right && nums[index] % 2 != nums[index+1] % 2 && nums[index] <= threshold && nums[index+1] <= threshold)
                index++;
            if(index < right - 1)
            {
                left = index + 1;
            }
            else
            {
                break;
            }
        }
        return right - left + 1;
    }

    
}
// @lc code=end

